package zconv

import (
	"time"
)

func MapToFloat64(v interface{}) float64 {
	if _, ok := v.(string); ok {
		return 0
	}
	if v != nil {
		return v.(float64)
	}
	return 0
}

func MapToInt64(v interface{}) int64 {
	if v != nil {
		if _, ok := v.(int64); ok {
			return v.(int64)
		}
		return int64(v.(float64))
	}
	return 0
}

func MapToUint32(v interface{}) uint32 {
	if v != nil {
		if _, ok := v.(int64); ok {
			return v.(uint32)
		}
		return uint32(v.(float64))
	}
	return 0
}

func MapToInt(v interface{}) int {
	if _, ok := v.(float64); !ok {
		return 0
	}
	if v != nil {
		return int(v.(float64))
	}
	return 0
}

func MapToUint64(v interface{}) uint64 {
	if _, ok := v.(float64); !ok {
		return 0
	}
	if v != nil {
		return uint64(v.(float64))
	}
	return 0
}

func MapToString(v interface{}) string {
	if v != nil {
		if _, ok := v.(string); !ok {
			return ""
		}
		return v.(string)
	}
	return ""
}

func MapToFloat(v interface{}) float32 {
	if _, ok := v.(float64); !ok {
		return 0
	}
	if v == nil {
		return float32(v.(float64))
	}
	return 0.0
}

func MapToTime(v interface{}) time.Time {
	if v != nil {
		if _, ok := v.(string); !ok {
			return time.Time{}
		}
		t := v.(string)
		t1, _ := time.Parse(time.DateTime, t)

		return t1
	}
	return time.Time{}
}
